<?php

namespace App\Http\Resources;

use Carbon\Carbon;

class DeviceListResource extends Resource
{
    /**
     * Transform the resource collection into an array.
     *
     * @param \Illuminate\Http\Request $request
     *
     * @return array
     */
    public function toArray($request)
    {
        return [
            'total' => $this->total,
            'finish_at' => $this->finish_at,
            'years' => (new Carbon($this->finish_at))->diffInYears($this->created_at),
            'price' => bcadd($this->price, 0, 2),
            'cost' => bcadd($this->cost, 0, 2)
        ];
    }
}
